<template>
  <el-dialog class="set_dialog" width="1200px" title="设置活动" :visible.sync="dialogVisible" :close-on-click-modal="false">
    <el-table :data="goodsList" @cell-dblclick="handle" style="width: 1500px">
    <el-table-column prop="id" label="id" width="80">
    </el-table-column>
    <el-table-column prop="color" label="颜色" width="80">
    </el-table-column>
    <el-table-column prop="spec" label="规格" sortable width="80">
    </el-table-column>
    <el-table-column prop="lease_time" label="租期" width="80">
        <template slot-scope="scope">
            <span>{{ scope.row.lease_time+'天' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="pact_type" label="租赁方式" width="150">
        <template slot-scope="scope">
            <span>{{ scope.row.pact_type==1?'租完续租-买断-归还':'租完即送' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="lease_price" label="租期价格" width="180">
      <template slot-scope="scope">
        <div v-if="!scope.row.isEdit">{{ scope.row.lease_price }}</div>
        <div v-else>
          <el-input v-model="scope.row.lease_price"></el-input>
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="day_price" label="日租金" width="180">
      <template slot-scope="scope">
        <div v-if="!scope.row.isEdit">{{ scope.row.day_price }}</div>
        <div v-else>
          <el-input v-model="scope.row.day_price"></el-input>
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="buyout_amount" label="市场价" width="180">
      <template slot-scope="scope">
        <div v-if="!scope.row.isEdit">{{ scope.row.buyout_amount }}</div>
        <div v-else>
          <el-input v-model="scope.row.buyout_amount"></el-input>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)">{{ scope.row.isEdit ? '完成' : '编辑' }}</el-button>
      </template>
    </el-table-column>
 </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
      <!-- <el-button size="small" type="primary" @click="submit">确 定</el-button> -->
    </div>
  </el-dialog>
</template>

<script>
import { getActivityList, addActivity } from '@/api/audit'
import { getGoodsDetail, setGoodsDetail } from '@/api/info'
const editVersion = (row) => {
        v.value = JSON.parse(JSON.stringify(row));
        row.editFlag = true;
    };
export default {
    
  data() {
    return {
      form: {
        id:'',
        lease_price:'',
        day_price:'',
        buyout_amount:'',
        editFlag: true,  // 可编辑标识
        isSubmit: false, // 是否点击确定标识
      },
      dialogVisible: false,
      goodsId: null,
      goodsList: []
    }
  },
  watch: {
    dialogVisible(val) {
        this.goodsId=this.$route.params.goodsId
      if (val) {
        getGoodsDetail(this.goodsId).then(res => {
            this.goodsList=res
        })
      }
    }
  },
  methods: {
    // 编辑
    handle(row, column, cell, event) {},
    handleClick(row) {
        if (row.isEdit) {
          this.$delete(row, 'isEdit')
            let params={
            id:row.id,
            lease_price:row.lease_price,
            day_price:row.day_price,
            buyout_amount:row.buyout_amount
          }
          console.log(params);
            setGoodsDetail(params).then(res=>{
            console.log(res);
          })
        } else {
          this.$set(row, 'isEdit', true);
          console.log(row);
        //   let params={
        //     id:row.id,
        //     lease_price:row.lease_price,
        //     day_price:row.day_price,
        //     buyout_amount:row.buyout_amount
        //   }
        //   setGoodsDetail().then(res=>{
        //     console.log(res);
        //   })
        }
    },
    submit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          const params = {
            goods_id: this.goodsId,
            activity_type: this.form.activity.join(',')
          }
          addActivity(params).then(res => {
            this.dialogVisible = false
            this.$emit('getList', true)
          })
        } else {
          this.$message({
            message: '请检查表单错误',
            type: 'error'
          })
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.tip {
  line-height: 35px;
  margin-bottom: 10px;
}
</style>
